*	************************************************************************
* 	File-Name: 		.do
*	Date:  			04/26/2016
*	Authors: 		Eugenie Dugoua
*	Data Used:  		Data_Merged_7_05.dta
*	Purpose:   		Analysis
*	Software:		Stata SE 12.1
*	Machine:		Stata for Windows through Linux Wine
*	************************************************************************

*	************************************************************************
*	DIRECTORY                                                               
*	************************************************************************
*ED file path
cap cd "/home/emd/Dropbox/Night Lights Validation (Eugenie, Ryan, Johannes)"

*JU FILE PATH, WD
cap cd "/home/jurpelai/Dropbox/Night Lights Validation (Eugenie, Ryan, Johannes)"

*RK File Path, WD
cap cd "C:/Users/Ryan/Dropbox/Night Lights Validation (Eugenie, Ryan, Johannes)"

clear all
use "./Data/Python_code_merging/Data_Merged_11_20_stata.dta"
label variable Distance "Distance to big city"
rename Distance distance

gen log_distance = log(distance+1)
gen logNLxDist = SH_sum_11_log * distance
gen logNLdummyxDist = SH_sum_11_logdummy * distance

gen logNLxlogDist = SH_sum_11_log * log_distance
gen logNLdummyxlogDist = SH_sum_11_logdummy * log_distance

codebook SH_sum_11_log distance electrified_hh_nbr
codebook SH_sum_11_log if electrified_hh_nbr != .
codebook latitude longitude

gen distance5 = 0
gen distance10 = 0
gen distance15 = 0
gen distance015 = 0
gen distance20= 0
gen distance020= 0
gen distance30 = 0
gen distance30more = 0
replace distance5 = 1 if distance < 5
replace distance10 = 1 if distance >= 5 & distance < 10
replace distance15 = 1 if distance >= 10 & distance < 15
replace distance015 = 1 if distance < 15
replace distance20 = 1 if distance >= 15 & distance < 20
replace distance020 = 1 if distance < 20
replace distance30 = 1 if distance >= 20 & distance < 30
replace distance30more = 1 if distance >= 30
label variable distance5 "Distance < 5 km"
label variable distance10 "Distance between 5 and 10 km"
label variable distance15 "Distance between 10 and 15 km"
label variable distance015 "Distance < 15 km"
label variable distance20 "Distance between 15 and 20 km"
label variable distance020 "Distance < 20 km"
label variable distance30 "Distance between 20 and 30 km"
label variable distance30more "Distance > 30 km"

sort distance




**************************************
* REGRESSION 1: MAIN             
**************************************
gen SH_sum_11_logxdistance5 = SH_sum_11_log * distance5
gen SH_sum_11_logxdistance10 = SH_sum_11_log * distance10
gen SH_sum_11_logxdistance15 = SH_sum_11_log * distance15
gen SH_sum_11_logxdistance20 = SH_sum_11_log * distance20
gen SH_sum_11_logxdistance30 = SH_sum_11_log * distance30
gen SH_sum_11_logxdistance30more = SH_sum_11_log * distance30more
gen SH_sum_11_logxdistance015 = SH_sum_11_log * distance015
label variable SH_sum_11_logxdistance5 "Lights X If distance < 5 km"
label variable SH_sum_11_logxdistance10 "Lights X If distance between 5 and 10 km"
label variable SH_sum_11_logxdistance15 "Lights X If distance between 10 and 15 km"
label variable SH_sum_11_logxdistance015 "Lights X If distance < 15 km"
label variable SH_sum_11_logxdistance20 "Lights X If distance between 15 and 20 km"
label variable SH_sum_11_logxdistance30 "Lights X If distance between 20 and 30 km"
label variable SH_sum_11_logxdistance30more "Lights X If distance > 30 km"
label variable log_distance "Distance (km) to major city in log"



local list_controls SH_sum_11_logxdistance5 SH_sum_11_logxdistance10 SH_sum_11_logxdistance15 SH_sum_11_logxdistance20 SH_sum_11_logxdistance30 

eststo clear
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log log_distance, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance5, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance10, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance15, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance20, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance30, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance30more, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log `list_controls', vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance015, vce(cluster St11)
esttab using "./Manuscript/Tables/results_distcities.tex", ///
replace b(%9.3f)  ///
stats( r2 N, ///
fmt( %9.3f %9.3g) ///
label( "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Dependent variable: Number of households with electricity (log). No fixed effects. ")


eststo clear
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log log_distance if SH_sum_11_log > 0, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance5 if SH_sum_11_log > 0, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance10  if SH_sum_11_log > 0, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance15  if SH_sum_11_log > 0, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance20  if SH_sum_11_log > 0, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance30 if SH_sum_11_log > 0, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance30more  if SH_sum_11_log > 0, vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log `list_controls', vce(cluster St11)
eststo: quietly reg electrified_hh_nbr_log SH_sum_11_log SH_sum_11_logxdistance015  if SH_sum_11_log > 0, vce(cluster St11)
esttab using "./Manuscript/Tables/results_distcities_onlypos.tex", ///
replace b(%9.3f)  ///
stats( r2 N, ///
fmt( %9.3f %9.3g) ///
label( "R-squared" "Observations")) booktabs eqlabels(none) ///
noconstant se label star(* 0.10 ** 0.05 *** 0.01) nomtitles ///
addnote ("Observations with strictly positive values of night lights" ///
"Dependent variable: Number of households with electricity (log)." /// 
"No fixed effects. Sub-sample of villages with night lights strictly positive.")






